Fix long string doubled quote parsing — swev-id: astropy__astropy-14598#101
Conversation
Test & Lint Results
|
noa-lucent
left a comment
There was a problem hiding this comment.
Summary:\n- Thanks for tightening the continuation handling and regression tests.\n- I spotted one more edge case: when a CONTINUE card has a comment separator but no comment text, yields an empty string, so the new guards treat it as a value fragment and splice the literal into the long-string payload.\n\nPlease change the guards to check (and update the remainder block accordingly) so we only recover whitespace when the comment field is completely absent.
Test & Lint Results (update)
|
noa-lucent
left a comment
There was a problem hiding this comment.
Thanks for tightening the guards. Confirmed both sites now check , so continuation whitespace recovery no longer triggers for empty-comment CONTINUE lines. Reconstructed values stay clean (no stray or spaces), and the existing regression tests still cover the edge cases.\n\nTests not rerun in this environment.
noa-lucent
left a comment
There was a problem hiding this comment.
Thanks for tightening the guards. Confirmed both if not comment sites now use comment is None, so continuation whitespace recovery no longer triggers for empty-comment CONTINUE lines. Reconstructed values stay clean (no stray & or spaces), and the existing regression tests still cover the edge cases.
Tests not rerun in this environment.
Summary
Card._splitObserved Failure
Silent data corruption on round-trip of FITS Card values containing doubled quotes near 80-col boundaries:
''appears within a larger value, mismatches occur across a range of lengths (often around continuation boundaries):fits.Card.fromstring(fits.Card("FOO", "x"*100 + "''", "comment").image).value→ returns a value ending with a single quote.fits.Card.fromstring(fits.Card("FOO", "x"*100 + "'' aaa", "comment").image).value→ truncates after the single quote.Reproduction Steps
Run any of the following in Python with astropy.io.fits:
Expected: All assertions pass.
Actual (pre-fix): Some assertions fail at lengths near continuation boundaries.
Stack Trace
No Python exception is raised; this is a silent parsing defect (logical data corruption). Therefore, no traceback is available. The failure is observable via round-trip mismatch as shown above.
Implementation Notes
astropy/io/fits/card.py,Card._split(long-image path) unescaped doubled quotes per CONTINUE chunk (replace("''", "'")), introducing stray single quotes at chunk boundaries that the final parser misinterpreted as terminators, leading to quote loss or truncation._format_value,_format_long_image) unchanged; they already double embedded quotes correctly.Tests
astropy/io/fits/tests/test_header.py:''round-trip, including within long continued values&or spaces)Fixes #71